package com.zpy;

import com.zpy.SmartChargeStation.iotdb.service.IoTDBService;
import com.zpy.SmartChargeStation.iotdb.service.impl.IoTDBServiceImpl;
import com.zpy.config.ServicesConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@Slf4j
@SpringBootApplication(scanBasePackages = "com.zpy")
public class MidApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(MidApplication.class, args);
        
        ServicesConfig servicesConfig = context.getBean(ServicesConfig.class);
        
        log.info("服务启动配置:");
        log.info("IoTDB 服务: {}", servicesConfig.getIotdb().isEnabled() ? "已启用" : "已禁用");
        log.info("MQTT 服务: {}", servicesConfig.getMqtt().isEnabled() ? "已启用" : "已禁用");
        log.info("Netty 服务: {}", servicesConfig.getNetty().isEnabled() ? "已启用" : "已禁用");
        
        // 根据配置决定启用哪些服务
        if (servicesConfig.getIotdb().isEnabled()) {
            log.info("正在初始化 IoTDB 服务...");
            // TODO:IoTDB服务初始化逻辑
            //添加IotDB服务初始化逻辑
            IoTDBServiceImpl iotDBService = context.getBean(IoTDBServiceImpl.class);
            boolean connected = iotDBService.Connection();
            if (connected) {
                log.info("IoTDB 服务初始化成功！");
            } else {
                log.error("IoTDB 服务初始化失败！");
            }
        }
        
        if (servicesConfig.getMqtt().isEnabled()) {
            log.info("正在初始化 MQTT 服务...");
            // TODO:MQTT服务初始化逻辑
        }
        
        if (servicesConfig.getNetty().isEnabled()) {
            log.info("正在初始化 Netty 服务...");
            // TODO:Netty服务初始化逻辑
        }
    }
}